/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.startup.musicstore.app.factory;

import com.startup.musicstore.model.*;
import com.startup.musicstore.services.crud.*;
import com.startup.musicstore.services.crud.Impl.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.joda.time.DateTime;

/**
 *
 * @author boniface
 */
public class AppFactory {
    
    
    // Create a Credit card with Name, balance, expiry date and credit Number 
     public static CreditCard getCreditCard(Map<String, String> details, BigDecimal balance, Date expiryDate) {
         CreditCard creditCard = new CreditCard();
         creditCard.setCreditNumber(details.get("number"));
         creditCard.setNameOnCreditCard(details.get("name"));
         creditCard.setBalance(balance);
         creditCard.setExpiryDate(expiryDate);
        return creditCard;
    }
     
     public static CustomerAddress getCustomerAddress(String streetAddress, String postalAddress){
         CustomerAddress address = new CustomerAddress();
         address.setPostalAddress(postalAddress);
         address.setStreetAddress(streetAddress);
         return address;
     }
     
     public static Customer getCustomer(Map<String,String> values, Date dateOfBirth){
         Customer customer = new Customer();
         Name name = new Name();
         name.setFirstName(values.get("firstName"));
         name.setLastName(values.get("lastName"));
         Contact contact = new Contact();
         contact.setContactNumber(values.get("contactNumber"));
         contact.setPhoneNumber(values.get("phoneNumber"));
         Demographic demographic = new Demographic();
         demographic.setDateOfBirth(dateOfBirth);
         demographic.setGender(values.get("race"));
         demographic.setRace(values.get("gender"));
         customer.setContact(contact);
         customer.setDemographic(demographic);
         customer.setName(name);
         customer.setCustomerNumber(values.get("customerNumber"));
         return customer;
     }
     
     public static Orders getOrder(List<OrderItem> items, int orderNumber, Date date){
         Orders order = new Orders();
         order.setOrderDate(date);
         order.setOrderItems(items);
         order.setOrderNumber(orderNumber);
         return order;
     }
     
     public static OrderItem getOrderItem(int quantity, Album album){
         
         OrderItem orderItem = new OrderItem();
         orderItem.setQuantity(quantity);
         orderItem.setAlbum(album);
         return orderItem;
     }
     
     public static AlbumCategory getAlbumCategory(String categoryName){
         AlbumCategory albumCategory = new AlbumCategory();
         albumCategory.setCategoryName(categoryName);
         return albumCategory;
     }
     
     public static Track getTrack(int number, String title, String url){
         SampleClip sampleClip = new SampleClip();
         sampleClip.setSampleUrl(url);
         Track track = new Track();
         track.setSampleClip(sampleClip);
         track.setTrackNumber(number);
         track.setTrackTitle(title);
         return track;
     }
     
     public static Album getAlbum(Map<String, String> values, List<Track> tracks, BigDecimal unitPrice){
         
         Review review = new Review();
         review.setDescription(values.get("description"));
         
         ArtistInformation artistInformation = new ArtistInformation();
         artistInformation.setFirstName(values.get("firstName"));
         artistInformation.setLastName(values.get("lastName"));

         MarketingInformattion marketingInformattion = new MarketingInformattion();
         marketingInformattion.setStatusOfMarketingInformation(values.get("statusOfInformation"));
         
         marketingInformattion.setArtistInformation(artistInformation);
         marketingInformattion.setReview(review);
  
         Album album = new Album();
         album.setAlbumTitle(values.get("albumTitle"));
         album.setTracks(tracks);
         album.setUnitPrice(unitPrice);
         album.setMarketingInformattion(marketingInformattion);
         
         return album;
     }

    public static ContactsService getContactsSericeInstance() {
        return new ContactsServiceImpl();
    }

    public static RatingsService getRatingServiceInstance() {
        return new RatingsServiceImpl();
    }

    public static WebAddressService getWebAddressService() {
        return new WebAddressServiceImpl();
    }

    public static AlbumsBoughtService getAlbumsBoughtServiceIndtance() {
        return new AlbumsBoughtServiceImpl();
    }

    public static List<Album> getAlbums() {
        return new ArrayList<Album>();
    }

    public static List<Customer> getCustomers() {
        return new ArrayList<Customer>();
    }

    public static InventoryService getInventryServiceInstance() {
        return new InventoryServiceImpl();
    }

    public static MostSalesService getMostSalesServiceInstance() {
        return new MostSalesServiceImpl();
    }

    public static UnpaidService getUnpaidService() {
        return new UnpaidServiceImpl();
    }

    public static OrderAmountService getOrderAmountService() {
        return new OrderAmountServiceImpl();
    }

    public static CustomerCreditCardService getCustomerCreditCardService() {
       return new CustomerCreditCardServiceImpl();
    }

    public static MarketingExceptionService getMarketingExceptionService() {
        return new MarketingExceptionServiceImpl();
    }

    public static Orders getOrderProcessing(Map<String, String> orderProcessing) {        
        OrderItem orderItem = new OrderItem();
        orderItem.setQuantity(Integer.parseInt(orderProcessing.get("quantity")));
        Album album = new Album();
        album.setId(new Long(orderProcessing.get("albumID")));
        orderItem.setAlbum(album);
        List<OrderItem> orderItems = new ArrayList<OrderItem>();
        orderItems.add(orderItem);
        
        Customer customer = new Customer();
        customer.setId(new Long(orderProcessing.get("customerID")));
        Orders order = new Orders();
        order.setCustomer(customer);
        order.setOrderDate(new DateTime(2012, 04, 12, 0, 0).toDate());
        order.setOrderNumber(Integer.parseInt(orderProcessing.get("orderNumber")));
        order.setOrderItems(null);
        order.setOrderItems(orderItems);        
        
        return order;
    }

    public static CustomerInvoice getCustomerInvoice(Map<String, String> values) {       
        CustomerInvoice customerInvoice = new CustomerInvoice();
        customerInvoice.setInvoiceDate(new DateTime(2012, 04, 13, 0, 0).toDate());
        customerInvoice.setInvoiceStatus(values.get("invoiceStatus"));
        Orders orders = new Orders();
        orders.setId(new Long(values.get("orderID")));
        customerInvoice.setOrder(orders);
        customerInvoice.setOrderAmount(new BigDecimal(values.get("orderAmount")));
        
        return customerInvoice;
    }

}
